package sz.szsmk.citizencard.ui.adapter;

import android.content.Context;
import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;


import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import java.text.NumberFormat;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import sz.szsmk.citizencard.DaggerApplication;
import sz.szsmk.citizencard.R;
import sz.szsmk.citizencard.log.L;
import sz.szsmk.citizencard.model.network.bean.response.QueryUserCardRes;
import sz.szsmk.citizencard.ui.activity.CitizenCardActivity;
import sz.szsmk.citizencard.util.ACache;
import sz.szsmk.citizencard.util.Constant;
import sz.szsmk.citizencard.util.JumpUtils;

import static android.view.View.GONE;
import static android.view.View.INVISIBLE;
import static android.view.View.VISIBLE;
import static sz.szsmk.citizencard.ui.adapter.CitizenCardvpAdatper.doubleToString;

/**
 * author : hyt
 * date : 2019/11/22
 * description : 这adapger下面 holder 里面的逻辑 是从原来的 照抄过来的
 */
public class ContentAdapter extends RecyclerView.Adapter{

    private static final int TOP = 0;
    private static final int ITEM = 1;
    private static final int BOTTOM = 2;

    private Context context;

    OnTopClick onTopClick;
    OnBottomClick onBottomClick;
    private Integer yscMoney;

    public Integer getYscMoney() {
        return yscMoney;
    }

    public void setYscMoney(Integer yscMoney) {
        this.yscMoney = yscMoney;
    }

    public ContentAdapter(Context context){
        this.context = context;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view ;
        switch (viewType){
            case TOP:
                return new TopHolder(LayoutInflater.from(context).inflate(R.layout.layout_routine_card_top, parent, false));
            case BOTTOM:
                view = LayoutInflater.from(context).inflate(R.layout.layout_routine_bottom,parent,false);
                return new BottomViewHolder(view);
            default:
                view = LayoutInflater.from(context).inflate(R.layout.layout_bind_citizen_card_info,parent,false);
                return new ItemViewHolder(view);
        }
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, final int position) {
        switch (getItemViewType(position)){
            case TOP:
                TopHolder topHolder = (TopHolder) holder;
                topHolder.update(topHolder);
                break;
            case BOTTOM:
                BottomViewHolder bottomViewHolder = (BottomViewHolder) holder;
                bottomViewHolder.update(bottomViewHolder);
                break;
            default:
                ItemViewHolder itemViewHolder = (ItemViewHolder) holder;
                itemViewHolder. upDateUI(itemViewHolder,cardServiceList.get(position-1));
                break;
        }
    }

    @Override
    public int getItemViewType(int position) {
        if(isCakeCard){
            if(position==0){
                return TOP;
            }else{
                return BOTTOM;
            }
        }else{
            if(position==0){
                return TOP;
            }else if(cardServiceList.size()+1==position){
                return BOTTOM;
            }else{
                return ITEM;
            }
        }
    }

    //这里有3种样式   经过筛选显示的数据    头    底部删除按钮
    @Override
    public int getItemCount() {

        if(isCakeCard){
            return 2;
        }else{
            return cardServiceList.size()+2;
        }
    }


    //一张整体 的卡
    QueryUserCardRes.DataBean userCardBean = new QueryUserCardRes.DataBean();

    //中间显示数据
    ArrayList<QueryUserCardRes.DataBean.CardDetailInfolistBean> cardServiceList = new ArrayList<>();

    //专有账户 显示TOP的数据
    QueryUserCardRes.DataBean.CardDetailInfolistBean privateAccount = null;

    //是否是蛋糕卡
    boolean isCakeCard = false;


    public void setData(QueryUserCardRes.DataBean data){
        this.userCardBean = data;
        if( !data.getCardDetailInfolist().isEmpty()){
            String cardNumber = data.getBindCardNo();
            //21500918，第5到8位：0918，是蛋糕卡
            if(cardNumber.length()>8){
                String cakeCard = cardNumber.substring(4,8);
                if("0918".equals(cakeCard)){
                    //蛋糕卡
                    isCakeCard = true;
                }else{
                    isCakeCard = false;
                }
                this.cardServiceList.clear();
                this.cardServiceList.addAll(this.userCardBean.getCardDetailInfolist());
                filterData();
            }else{
                this.cardServiceList.clear();
                this.cardServiceList.addAll(this.userCardBean.getCardDetailInfolist());
                filterData();
            }
        }
        notifyDataSetChanged();
    }

    public class TopHolder extends RecyclerView.ViewHolder{

        //蛋糕卡 layout
        RelativeLayout rl_cakelayout;
        //蛋糕卡充值
        TextView tv_Cakecard_recharge;

        //云闪充layout
        RelativeLayout rl_cloudlayout;

        //立即充值
        TextView tv_card_recharge;
        //账户余额合计
        RelativeLayout private_account_layout;
        //游玩足迹
        LinearLayout footprint_rl;
        //去认证
        TextView card_speci_tv;
        //企服卡账户
        LinearLayout qfkzh;
        //企服卡修改密码
        TextView tv_changePwd_qfk;
        //提示
        TextView tv_pwdTip;
        //提示
        LinearLayout ll_verificationed;
        //未验证
        TextView tv_noVerification;
        //修改密码
        TextView tv_changePwd_qfk2;
        //企服卡账户金额
        TextView card_qfkzh_money;
        //文化账户金额
        TextView card_whzh_money;
        //文化账户
        LinearLayout whzh;

        LinearLayout dgk_lin;
        //账户余额合计
        TextView card_allmoney;
        //蛋糕卡账户金额
        TextView card_dgkzh_money;
        //电子钱包金额
        TextView card_dzqb_money;
        //电子钱包  可用商家
        TextView dzcksj_tv;
        //蛋糕卡 可用商家
        TextView dgkkysj_tv;

        RelativeLayout  dgk;

        //账户明细
        TextView account_detail;
        //账户余额
        TextView account_money;
        //小字账户余额
        TextView card_money;
        //蛋糕卡余额
        TextView cake_balance;
        //可用商家
        TextView kysj_cake;

        public TopHolder(View itemView) {
            super(itemView);
            private_account_layout = itemView.findViewById(R.id.private_account_layout);
            tv_card_recharge = itemView.findViewById(R.id.tv_card_recharge);
            footprint_rl = itemView.findViewById(R.id.footprint_rl);
            card_speci_tv = itemView.findViewById(R.id.card_speci_tv);
            qfkzh = itemView.findViewById(R.id.qfkzh);
            tv_changePwd_qfk = itemView.findViewById(R.id.tv_changePwd_qfk);
            tv_pwdTip = itemView.findViewById(R.id.tv_pwdTip);
            ll_verificationed = itemView.findViewById(R.id.ll_verificationed);
            tv_noVerification = itemView.findViewById(R.id.tv_noVerification);
            tv_changePwd_qfk2 = itemView.findViewById(R.id.tv_changePwd_qfk2);
            card_qfkzh_money = itemView.findViewById(R.id.card_qfkzh_money);
            card_whzh_money = itemView.findViewById(R.id.card_whzh_money);
            whzh = itemView.findViewById(R.id.whzh);
            dgk_lin = itemView.findViewById(R.id.dgk_lin);
            card_allmoney = itemView.findViewById(R.id.card_allmoney);
            card_dgkzh_money = itemView.findViewById(R.id.card_dgkzh_money);
            card_dzqb_money = itemView.findViewById(R.id.card_dzqb_money);
            dzcksj_tv = itemView.findViewById(R.id.dzcksj_tv);
            dgkkysj_tv = itemView.findViewById(R.id.dgkkysj_tv);
            rl_cakelayout = itemView.findViewById(R.id.rl_cakelayout);
            rl_cloudlayout = itemView.findViewById(R.id.rl_cloudlayout);
            tv_Cakecard_recharge = itemView.findViewById(R.id.tv_Cakecard_recharge);
            dgk = itemView.findViewById(R.id.dgk);
            account_detail=itemView.findViewById(R.id.account_detail);
            account_money=itemView.findViewById(R.id.account_money);
            card_money=itemView.findViewById(R.id.card_money);
            cake_balance=itemView.findViewById(R.id.cake_balance);
            kysj_cake=itemView.findViewById(R.id.kysj_cake);
        }

        public void update(TopHolder holder){
            holder.rl_cakelayout.setVisibility(GONE);
            holder.rl_cloudlayout.setVisibility(GONE);
            holder.dgk.setVisibility(GONE);

            holder.private_account_layout.setVisibility(GONE);
            holder.footprint_rl.setVisibility(GONE);

            if(userCardBean.getFootPrintStatus()==1){
                holder.footprint_rl.setVisibility(VISIBLE);
            }

            //是否是 蛋糕卡
            if(isCakeCard){
                holder.rl_cakelayout.setVisibility(VISIBLE);
                holder.private_account_layout.setVisibility(VISIBLE);
                holder.tv_Cakecard_recharge.setOnClickListener(v->onTopClick.onDgk_recharge());
                holder.dgk.setVisibility(VISIBLE);
            }else{
                holder.private_account_layout.setVisibility(VISIBLE);
                holder.rl_cloudlayout.setVisibility(VISIBLE);
            }

            if(cardServiceList.size()>0){
                updateTop(holder);
                //绑定事件

            }
            if(onTopClick!=null){
                holder.tv_card_recharge.setOnClickListener(v->onTopClick.onCard_recharge());
                holder.tv_changePwd_qfk.setOnClickListener(v->onTopClick.onChangePwd_qfk());
                holder.tv_changePwd_qfk2.setOnClickListener(v->onTopClick.onChangePwd_qfk());
                holder.footprint_rl.setOnClickListener(v->onTopClick.onFootprint_rl());
                holder.card_speci_tv.setOnClickListener(v->onTopClick.onCard_speci_tv());
                holder.dzcksj_tv.setOnClickListener(v->onTopClick.onDzcksj_tv());
                holder.dgkkysj_tv.setOnClickListener(v->onTopClick.onDgkkysj_tv());
                holder.account_detail.setOnClickListener(v->onTopClick.accountDetail());
                holder.kysj_cake.setOnClickListener(v->onTopClick.kysj_cake());
            }

        }
    }

    public interface OnTopClick{
        //立即充值
        void onCard_recharge();
        //修改密码 企服卡
        void onChangePwd_qfk();
        //游玩足迹
        void onFootprint_rl();
        //去认证
        void onCard_speci_tv();
        //电子钱包  可用商家
        void onDzcksj_tv();
        //蛋糕卡 可用商家
        void onDgkkysj_tv();
        //蛋糕卡 充值
        void onDgk_recharge();
        //账户明细跳转
        void accountDetail();

        void kysj_cake();
    }

    public class ItemViewHolder extends RecyclerView.ViewHolder{

        private ImageView service_icon;
        private TextView title, sub_title, action;
        private RelativeLayout status_open_layout, status_closer_layout;

        private TextView status_btn, card_tyhm_times, card_tyhm_endtimes,tv_sycs;
        private TextView tip_can_go, tip_hotel, tip_search, tip_history;
        private TextView btn_open_service, txt_desc,tv_packageTypeName;
        private String access_token;



        public ItemViewHolder(View itemView) {
            super(itemView);
            service_icon = (ImageView) itemView.findViewById(R.id.service_icon);
            title = (TextView) itemView.findViewById(R.id.title);
            sub_title = (TextView) itemView.findViewById(R.id.sub_title);
            action = (TextView) itemView.findViewById(R.id.action);
            status_open_layout = (RelativeLayout) itemView.findViewById(R.id.status_open_layout);
            status_btn = (TextView) itemView.findViewById(R.id.status_btn);
            card_tyhm_times = (TextView) itemView.findViewById(R.id.card_tyhm_times);
            card_tyhm_endtimes = (TextView) itemView.findViewById(R.id.card_tyhm_endtimes);
            tv_sycs = itemView.findViewById(R.id.tv_sycs);
            tip_can_go = (TextView) itemView.findViewById(R.id.tip_can_go);
            tip_hotel = (TextView) itemView.findViewById(R.id.tip_hotel);
            tip_search = (TextView) itemView.findViewById(R.id.tip_search);
            tip_history = (TextView) itemView.findViewById(R.id.tip_history);
            status_closer_layout = (RelativeLayout) itemView.findViewById(R.id.status_closer_layout);

            btn_open_service = (TextView) itemView.findViewById(R.id.btn_open_service);
            txt_desc = (TextView) itemView.findViewById(R.id.txt_desc);

            tv_packageTypeName = itemView.findViewById(R.id.tv_packageTypeName);


        }

        private void upDateUI(ItemViewHolder itemViewHolder, QueryUserCardRes.DataBean.CardDetailInfolistBean itemBean) {
            title.setText(itemBean.getFuncName());
            if ( (!TextUtils.isEmpty(itemBean.getFuncCode()) ) &&  ( itemBean.getFuncCode().equals("01") || itemBean.getFuncCode().equals("02")
                    || itemBean.getFuncCode().equals("03") || itemBean.getFuncCode().equals("08"))) {
                switch (itemBean.getFuncCode()) {
                    case "01":
                        itemViewHolder.service_icon.setImageResource(R.drawable.home_grid_xxnk);
                        break;
                    case "02":
                        itemViewHolder. service_icon.setImageResource(R.drawable.home_grid_ylnk);
                        break;
                    case "03":
                        itemViewHolder.service_icon.setImageResource(R.drawable.card_qzwwk);   //蓝色那个icon
                        break;
                    case "08":
                        itemViewHolder.service_icon.setImageResource(R.drawable.home_grid_zzk);
                        break;
                }

                if (itemBean.getCardState().equals("0")) {
                    itemViewHolder.status_closer_layout.setVisibility(VISIBLE);
                    itemViewHolder.status_open_layout.setVisibility(GONE);
                    itemViewHolder.action.setTextColor(0xff777777);
                    String stateName = itemBean.getStateName();
                    if (stateName != null) {
                        itemViewHolder.action.setText(itemBean.getStateName());
                    }
                    itemViewHolder.btn_open_service.setText("立即办理");
                } else {
                    itemViewHolder.status_closer_layout.setVisibility(GONE);
                    itemViewHolder.status_open_layout.setVisibility(VISIBLE);
                    itemViewHolder.action.setTextColor(0xff00aaff);
                    itemViewHolder.action.setText("更多详情");

                    itemViewHolder.status_btn.setText(itemBean.getStateName());

                    itemViewHolder.tv_sycs.setVisibility(VISIBLE);
                    itemViewHolder.card_tyhm_times.setVisibility(VISIBLE);

                    itemViewHolder.card_tyhm_times.setText(itemBean.getSpareTimes() );

                    itemViewHolder.card_tyhm_endtimes.setText(itemBean.getEndTime());

                    itemViewHolder.tv_packageTypeName.setText(itemBean.getPackageTypeName());


                    if(!TextUtils.isEmpty(itemBean.getSpareTimes())){
                        itemViewHolder.card_tyhm_times.setText(itemBean.getSpareTimes());
                    }

                    switch (itemBean.getFuncCode()) {
                        case "01":
                            itemViewHolder.tip_can_go.setVisibility(VISIBLE);
                            itemViewHolder.tip_hotel.setVisibility(GONE);
                            itemViewHolder.tip_search.setVisibility(VISIBLE);
                            itemViewHolder.tip_history.setVisibility(GONE);
                            break;
                        case "02":
                            itemViewHolder.tip_can_go.setVisibility(GONE);
                            itemViewHolder.tip_hotel.setVisibility(GONE);
                            itemViewHolder.tip_search.setVisibility(GONE);
                            itemViewHolder.tip_history.setVisibility(GONE);
                            break;
                        case "03":
                            itemViewHolder.tip_can_go.setVisibility(VISIBLE);
                            itemViewHolder.tip_hotel.setVisibility(GONE);
                            itemViewHolder.tip_search.setVisibility(VISIBLE);
                            itemViewHolder.tip_history.setVisibility(GONE);
                            break;
                        case "08":
                            itemViewHolder.tip_can_go.setVisibility(VISIBLE);
                            itemViewHolder.tip_hotel.setVisibility(GONE);
                            itemViewHolder.tip_search.setVisibility(GONE);
                            itemViewHolder.tip_history.setVisibility(VISIBLE);
                            break;
                    }

                    if ("已过期".equals(itemBean.getStateName())) {
                        itemViewHolder.status_closer_layout.setVisibility(VISIBLE);
                        itemViewHolder.btn_open_service.setText("再次办理");
                        itemViewHolder.tip_can_go.setVisibility(GONE);
                        itemViewHolder.tip_hotel.setVisibility(GONE);
                        itemViewHolder.tip_search.setVisibility(GONE);
                        itemViewHolder.tip_history.setVisibility(GONE);
                    }
                }
            } else {
                itemViewHolder.status_closer_layout.setVisibility(GONE);
                itemViewHolder.status_open_layout.setVisibility(GONE);

                if (!TextUtils.isEmpty(itemBean.getFuncCode())  && itemBean.getFuncCode().equals("05")) {
                    itemViewHolder.service_icon.setImageResource(R.drawable.card_tsg);
                    itemViewHolder.action.setTextColor(0xff777777);
                    itemViewHolder.action.setText(itemBean.getStateName());
                }
            }
            itemViewHolder.action.setOnClickListener(v->onItemClick(itemViewHolder.action,itemBean));
            itemViewHolder.btn_open_service.setOnClickListener(v->onItemClick(itemViewHolder.btn_open_service,itemBean));
            itemViewHolder.tip_can_go.setOnClickListener(v->onItemClick(itemViewHolder.tip_can_go,itemBean));
            itemViewHolder.tip_hotel.setOnClickListener(v->onItemClick(itemViewHolder.tip_hotel,itemBean));
            itemViewHolder.tip_search.setOnClickListener(v->onItemClick(itemViewHolder.tip_search,itemBean));
            itemViewHolder.tip_history.setOnClickListener(v->onItemClick(itemViewHolder.tip_history,itemBean));
        }
    }


    public interface OnBottomClick{
        void onBtnDelCard();
    }

    public class BottomViewHolder extends RecyclerView.ViewHolder{

        Button btn_deleteCard;

        public BottomViewHolder(View itemView) {
            super(itemView);
            btn_deleteCard = itemView.findViewById(R.id.btn_deleteCard);
        }

        public void update(BottomViewHolder holder){
            if (Constant.isBind) {
                btn_deleteCard.setVisibility(View.VISIBLE);
            } else {
                btn_deleteCard.setVisibility(View.GONE);
            }
            btn_deleteCard.setOnClickListener(v->{
                if(onBottomClick!=null){
                    onBottomClick.onBtnDelCard();
                }
            });
        }


    }


    //过滤数据 返回  显示的 数据   根据显示头的 数据 删减
    private void filterData() {
        //（01 休闲年卡，02 园林年卡，03 亲子卡，04 专有账户，05 图书馆，06 吴江旅游，07 月票，08 转转卡）
        //获取   01 休闲年卡  02 园林年卡  03 亲子卡   05 图书馆
        //04 专有账户  获取 里面的数据
        //不要循环List 在循环中remove元素  否则会 抛出 ConcurrentModificationException 异常
        try{
            Iterator<QueryUserCardRes.DataBean.CardDetailInfolistBean> it = this.cardServiceList.iterator();
             while(it.hasNext()){
                QueryUserCardRes.DataBean.CardDetailInfolistBean bean = it.next();
                //这里 判空  直接 remove
                if(TextUtils.isEmpty(bean.getFuncCode())){
                    it.remove();
                    continue;
                }
                switch (bean.getFuncCode()){
                    //  屏蔽 吴江旅游卡 与 月票
                    case "06":
                    case "07":
                        it.remove();
                        break;
                    case "08":
                        //转转卡不开通就屏蔽
                        if(bean.getCardState().equals("0")){
                            it.remove();
                        }
                        break;
                    case "04":
                        //专有账户
                        privateAccount =  bean.clone();
                        it.remove();
                        break;
                    default:
                        break;
                }
            }
        }catch (Exception ex){
            ex.printStackTrace();
        }
    }

    //头部数据
    public void updateTop(TopHolder holder){
        //根据专有账户的 开通状态   显示专有账户数据
        //（0 未开通，1 已开通，2 已过期）
        holder.private_account_layout.setVisibility(GONE);
        if(privateAccount != null &&  !TextUtils.isEmpty(privateAccount.getCardState()) &&
                "1".equals(privateAccount.getCardState())      ){
            //默认隐藏
            holder.tv_pwdTip.setVisibility(GONE);

            holder.private_account_layout.setVisibility(VISIBLE);

            //专有账户 是否验证
            holder.qfkzh.setVisibility(userCardBean.getIsBusinessOpen()==1 ? VISIBLE : GONE);
            if (userCardBean.getIsVerified() == 1) {
                //去认证按钮  隐藏
                holder.card_speci_tv.setVisibility(GONE);
                //修改密码按钮 显示
                holder.tv_changePwd_qfk.setVisibility(VISIBLE);
                if(userCardBean.getIsBusinessOpen()==1){
                    //文字提示
                    holder.tv_pwdTip.setVisibility(VISIBLE);
                }
                //验证后
                holder.ll_verificationed.setVisibility(VISIBLE);
                holder.tv_noVerification.setVisibility(GONE);

                //如果企服卡  没开通    文化账户那一行  修改密码 显示
                if(userCardBean.getIsBusinessOpen()!=1){
                    holder.tv_changePwd_qfk2.setVisibility(VISIBLE);
                }else{
                    holder.tv_changePwd_qfk2.setVisibility(GONE);
                }
                holder.card_qfkzh_money.setVisibility(VISIBLE);
                holder.card_qfkzh_money.setText(toDouble(userCardBean.getSpecialAccounts().getBusinessBalance()) + "");
            } else {
                holder.card_speci_tv.setVisibility(VISIBLE);
                holder.card_speci_tv.setText("去认证");
                holder.tv_changePwd_qfk.setVisibility(GONE);
                //验证后
                holder.ll_verificationed.setVisibility(GONE);
                holder.tv_noVerification.setVisibility(VISIBLE);

                holder.card_qfkzh_money.setText("-");
                holder.card_qfkzh_money.setVisibility(GONE);

                if("1".equals(userCardBean.getIsCultureOpen())){
                    holder.card_whzh_money.setText("-");
                }else{
                    holder.card_whzh_money.setText("未开通");
                }
            }

            //文化账户是否开通
            if("1".equals(userCardBean.getIsCultureOpen())){
                holder.card_whzh_money.setText(toDouble(userCardBean.getSpecialAccounts().getCultureBalance())+"元");
                holder.whzh.setVisibility(VISIBLE);
            }else{
                holder.whzh.setVisibility(GONE);
            }

            //账户总余额
            holder.account_money.setText(toDouble(userCardBean.getCardTotalBalance())+"元");

            //云闪充
            //String s = changeF2Y(yscMoney.toString());
            if (yscMoney!=null)
            holder.card_money.setText("云闪充钱包："+ toDouble(yscMoney) +"元");

            //蛋糕卡
            if (userCardBean.getCakeCardBalance()==null){
                holder.cake_balance.setText("0元");
            }else
                holder.cake_balance.setText(toDouble(Integer.parseInt(userCardBean.getCakeCardBalance()))+"元");

            holder.dgk_lin.setVisibility(userCardBean.getCakeCardIsOpen() == 0 ? GONE : VISIBLE);
            holder.card_allmoney.setText(changeF2Y(userCardBean.getCardTotalBalance() + ""));
            //holder.card_dgkzh_money.setText(changeF2Y(userCardBean.getCakeCardBalance()!=null? userCardBean.getCakeCardBalance():0 + ""));
            if (userCardBean.getCakeCardBalance()!=null)
            holder.card_dgkzh_money.setText(toDouble(Integer.parseInt(userCardBean.getCakeCardBalance()))+"元");
            holder.card_dzqb_money.setText(toDouble(userCardBean.getCardBalance())+"元");
        }
    }


    private String toDouble(Integer amount){
        if (amount==0||amount==null)
            return "0";
        else {
            double balance =(double) amount;
            double mBalance = balance / 100;
            String balancestr = doubleToString(mBalance);
            return balancestr;
        }
    }
    private String changeF2Y(String amount) {
        NumberFormat format = NumberFormat.getInstance();
        try {
            Number number = format.parse(amount);
            double temp = number.doubleValue() / 100.0;
            format.setGroupingUsed(false);
            // 设置返回的小数部分所允许的最大位数
            format.setMaximumFractionDigits(2);
            amount = format.format(temp);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return "￥"+amount;
    }

    public void setOnTopClick(OnTopClick onTopClick) {
        this.onTopClick = onTopClick;
    }

    private void onItemClick(View view,QueryUserCardRes.DataBean.CardDetailInfolistBean itemBean){
        String access_token = ACache.get(DaggerApplication.getIns()).getAsString("access_token");

        String webUrl = "";
        Bundle bundle = new Bundle();

        int id = view.getId();
        if (id == R.id.action) {//                查看详情可用时
            if (!itemBean.getCardState().equals("0") && (itemBean.getFuncCode().equals("01") || itemBean.getFuncCode().equals("02")
                    || itemBean.getFuncCode().equals("03") || itemBean.getFuncCode().equals("08"))) {
                if (itemBean.getFuncCode().equals("02")) {
                    webUrl = Constant.BASE_URL + "app-front-end/#/gardenCard/main?access_token=" + access_token;
                    bundle.putString("url", webUrl);
                    JumpUtils.jumptoNatvie(DaggerApplication.getIns(), "webView", 0, bundle);
                } else if (itemBean.getFuncCode().equals("01")) {
                    webUrl = Constant.BASE_URL + "app-front-end/#/card/main?access_token=" + access_token;
                    bundle.putString("url", webUrl);
                    JumpUtils.jumptoNatvie(DaggerApplication.getIns(), "webView", 0, bundle);

                } else if (itemBean.getFuncCode().equals("03")) {
                    webUrl = Constant.BASE_URL + "app-front-end/#/familycard/main";
                    bundle.putString("url", webUrl);
                    JumpUtils.jumptoNatvie(DaggerApplication.getIns(), "webView", 0, bundle);

                } else if (itemBean.getFuncCode().equals("05")) {
                    Toast.makeText(DaggerApplication.getIns(), "图书馆", Toast.LENGTH_SHORT).show();

                } else if (itemBean.getFuncCode().equals("06")) {
                    Toast.makeText(DaggerApplication.getIns(), "吴江旅游年卡", Toast.LENGTH_SHORT).show();

                } else if (itemBean.getFuncCode().equals("07")) {
                    Toast.makeText(DaggerApplication.getIns(), "月票", Toast.LENGTH_SHORT).show();

                }
            }
        } else if (id == R.id.btn_open_service) {
            if (itemBean.getFuncCode().equals("02")) {
                webUrl = Constant.BASE_URL + "app-front-end/#/gardenCard/main?access_token=" + access_token;
                bundle.putString("url", webUrl);
                JumpUtils.jumptoNatvie(DaggerApplication.getIns(), "webView", 0, bundle);
            } else if (itemBean.getFuncCode().equals("01")) {
                webUrl = Constant.BASE_URL + "app-front-end/#/card/main?access_token=" + access_token;
                bundle.putString("url", webUrl);
                JumpUtils.jumptoNatvie(DaggerApplication.getIns(), "webView", 0, bundle);

            } else if (itemBean.getFuncCode().equals("03")) {
                webUrl = Constant.BASE_URL + "app-front-end/#/familycard/main?access_token=" + access_token;
                bundle.putString("url", webUrl);
                JumpUtils.jumptoNatvie(DaggerApplication.getIns(), "webView", 0, bundle);

            } else if (itemBean.getFuncCode().equals("05")) {
                Toast.makeText(DaggerApplication.getIns(), "图书馆", Toast.LENGTH_SHORT).show();

            } else if (itemBean.getFuncCode().equals("06")) {
                Toast.makeText(DaggerApplication.getIns(), "吴江旅游年卡", Toast.LENGTH_SHORT).show();

            } else if (itemBean.getFuncCode().equals("07")) {
                Toast.makeText(DaggerApplication.getIns(), "月票", Toast.LENGTH_SHORT).show();

            }

//                四个底部小选项
        } else if (id == R.id.tip_can_go) {
            if (itemBean.getFuncCode().equals("03")) {
                webUrl = Constant.BASE_URL + "app-front-end/#/familyCard/availableScenerySpot?isMain=1";
                bundle.putString("url", webUrl);
                bundle.putString(Constant.TITLE, "");
            } else {
                webUrl = Constant.BASE_URL + "app-front-end/#/card/availableScenerySpot?access_token="
                        + access_token + "&isMain=1" + "&cardNo=" + this.userCardBean.getBindCardNo();
                L.e(Constant.TAG, "可取景点url----" + webUrl);
                bundle.putString("url", webUrl);
            }

            JumpUtils.jumptoNatvie(DaggerApplication.getIns(), "webView", 0, bundle);
        } else if (id == R.id.tip_hotel) {
            webUrl = Constant.BASE_URL + "app-front-end/#/card/availableHotel?access_token=" + access_token + "&isMain=1";
            bundle.putString("url", webUrl);
            JumpUtils.jumptoNatvie(DaggerApplication.getIns(), "webView", 0, bundle);
        } else if (id == R.id.tip_search) {
            if (itemBean.getFuncCode().equals("03")) {
                webUrl = Constant.BASE_URL + "app-front-end/#/familyCard/queryScenerySpotBook?access_token=" + access_token + "&isMain=1";
            } else {
                webUrl = Constant.BASE_URL + "app-front-end/#/card/queryScenerySpotBook?access_token=" + access_token + "&isMain=1";
            }
            bundle.putString("url", webUrl);
            JumpUtils.jumptoNatvie(DaggerApplication.getIns(), "webView", 0, bundle);
        } else if (id == R.id.tip_history) {
            webUrl = Constant.BASE_URL + "app-front-end/#/familycard/main";
            bundle.putString("url", webUrl);
            JumpUtils.jumptoNatvie(DaggerApplication.getIns(), "webView", 0, bundle);
        }
    }

    public void setOnBottomClick(OnBottomClick onBottomClick) {
        this.onBottomClick = onBottomClick;
    }


}